<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>网页应用鉴权</title>
    <script type="text/javascript" src="{__SGHOME_PATH}js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="{__SGHOME_PATH}js/h5-js-sdk-1.5.16.js"></script>
</head>

<body>

</body>

<script type="text/javascript">

$(function (){
    console.log("start apiAuth");
    if (!window.h5sdk) {
        console.log("invalid h5sdk");
        alert("please open in feishu");
        return;
    }
    // 通过error接口处理API验证失败后的回调
    window.h5sdk.error((err) => {
        throw ("h5sdk error:", JSON.stringify(err));
    });
    // 调用config接口进行鉴权
    window.h5sdk.config({
        appId: '{$parameters.appid}',
        timestamp: {$parameters.timestamp},
        nonceStr: '{$parameters.noncestr}',
        signature: '{$parameters.signature}',
        jsApiList: [
            "tt.getSystemInfo",
            "tt.showActionSheet",
            "tt.previewImage",
            "tt.showToast"
        ],
        //鉴权成功回调
        onSuccess: (res) => {
            console.log(`21213213212131312config success: ${JSON.stringify(res)}`);
        },
        //鉴权失败回调
        onFail: (err) => {
            console.log(`3config failed: ${JSON.stringify(err)}`);
        },
    });
    console.log({
        appId: '{$parameters.appid}',
        jsapi_ticket: '{$parameters.jsapi_ticket}',
        nonceStr: '{$parameters.noncestr}',
        timestamp: {$parameters.timestamp},
        url: '{$parameters.url}',
        signature: '{$parameters.signature}',
        jsApiList: [
            "tt.getSystemInfo",
            "tt.showActionSheet",
            "tt.previewImage",
            "tt.showToast"
        ]
    })
    window.h5sdk.ready(() => {
        // window.h5sdk.ready回调函数在环境准备就绪时触发
        // 调用 getUserInfo API 获取已登录用户的基本信息，详细文档参见https://open.feishu.cn/document/uYjL24iN/ucjMx4yNyEjL3ITM
        console.log(11111);
        tt.getUserInfo({
            // getUserInfo API 调用成功回调
            success(res) {
                console.log(`111getUserInfo success: ${JSON.stringify(res)}`);
            },
            // getUserInfo API 调用失败回调
            fail(err) {
                console.log(`222getUserInfo failed:`, JSON.stringify(err));
            },
        });
        tt.setScreenBrightness({
            "value": 0.8,
            success(res) {
                console.log(4444,JSON.stringify(res));
            },
            fail(res) {
                console.log(`3333setScreenBrightness fail: ${JSON.stringify(res)}`);
            }
        });
    });
});
</script>
</html>